package com.controller.manage;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.po.Role;
import com.po.User;
import com.po.UserRole;
import com.service.manage.UserRoleService;

@Controller
@RequestMapping("/jsp/manager")
public class UserRoleController {

	@Resource(name="userRoleServiceImp")
	public UserRoleService userRoleService;
	
	@ResponseBody
	@RequestMapping(value="/getUserRoleList")
	public List<User> getUserList(User user,Integer page,Integer rows){
		
		user.setPage((page-1)*rows);
		user.setRows(rows);
		
		List<User> list = userRoleService.getUserole(user);
		return list;
	}
	
	@ResponseBody
	@RequestMapping(value="/getUserRole")
	public List<Role> getUseRoleList(Role role){
		
		List<Role> list = userRoleService.getRolesList();
		return list;
	} 
	
	@ResponseBody
	@RequestMapping(value="/addUsersRole")
	public int AddUserRole(String userid,String roleid){
		
		User user = new User();
		user.setUser_id(userid);
		user.setUser_style_id(roleid);
		UserRole userrole = new UserRole();
		userrole.setUser_id(userid);
		userrole.setRole_id(roleid);
		int result = userRoleService.updateUsersReg(user, userrole);
		
		return result;
	}
	
	@ResponseBody
	@RequestMapping(value="/getRolesListArray")
	public List<UserRole> getRolesListArray(User user){
		
		List<UserRole> list = userRoleService.getRolesListArray(user);
		return list;
	} 
}
